package com.elm.controller;

import com.elm.po.Orders;
import com.elm.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/createOrders")
    public int createOrders(@RequestParam Integer businessId,
                           @RequestParam Integer daId,
                           @RequestParam Double orderTotal) {
        return ordersService.createOrders( businessId, daId, orderTotal);
    }

    @GetMapping("/getOrdersById")
    public Orders getOrdersById(@PathVariable Integer orderId) {
        return ordersService.getOrdersById(orderId);
    }

    @GetMapping("/getOrdersByUserId")
    public List<Orders> getOrdersByUserId() {
        return ordersService.getOrdersByUserId();
    }

    @PostMapping("/addComment")
    public int addComment(@RequestParam Integer orderId,
                         @RequestParam String comment,
                         @RequestParam Integer star) {
        return ordersService.addComment(orderId, comment, star);
    }

    @GetMapping("/getAllCommentsByBusinessId")
    public List<Orders> getAllCommentsByBusinessId(@PathVariable Integer businessId) {
        return ordersService.getAllCommentsByBusinessId(businessId);
    }

    @GetMapping("/getAllComments")
    public List<Orders> getAllComments() {
        return ordersService.getAllComments();
    }

    @DeleteMapping("/deleteComment")
    public int deleteComment(@PathVariable Integer orderId) {
        return ordersService.deleteComment(orderId);
    }

    @GetMapping("/getAllOrders")
    public List<Orders> getAllOrders(@PathVariable Integer businessId) {
        return ordersService.getAllOrders(businessId);
    }

    @GetMapping("/getAllPaidOrders")
    public List<Orders> getAllPaidOrders(@PathVariable Integer businessId) {
        return ordersService.getAllPaidOrders(businessId);
    }

    @GetMapping("/getAllEndedOrders")
    public List<Orders> getAllEndedOrders(@PathVariable Integer businessId) {
        return ordersService.getAllEndedOrders(businessId);
    }

    @PutMapping("/handleOrders")
    public int handleOrders(@RequestParam Integer businessId,
                           @RequestParam Integer orderId) {
        return ordersService.handleOrders(businessId, orderId);
    }
}